package com.jhhc.EngineeringSafety.Calculate.Forecast.service.impl;

import com.jhhc.EngineeringSafety.Calculate.Forecast.dao.BDMS_CALCULATESCHEME_M3Mapper;
import com.jhhc.EngineeringSafety.Calculate.Forecast.entity.param.CalSchemeParam;
import com.jhhc.EngineeringSafety.Calculate.Forecast.entity.result.CalSchemeInfo;
import com.jhhc.EngineeringSafety.Calculate.Forecast.service.BDMS_CALCULATESCHEME_M33Service;
import com.jhhc.EngineeringSafety.Calculate.Forecast.entity.BDMS_CALCULATESCHEME_M;
import com.jhhc.utils.JsonResult;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * (BdmsCalculateschemeM)表服务实现类
 *
 * @author makejava
 * @since 2023-06-19 18:03:00
 */
@Service
public class BDMS_CALCULATESCHEME_M33ServiceImpl implements BDMS_CALCULATESCHEME_M33Service {

    @Resource
    private BDMS_CALCULATESCHEME_M3Mapper bdms_calculatescheme_m3Mapper;


    @Override
    public JsonResult selectOne(CalSchemeParam calSchemeParam) {
        JsonResult jsonResult = new JsonResult();
        CalSchemeInfo calSchemeInfo =  new CalSchemeInfo();
        BDMS_CALCULATESCHEME_M bdms_calculatescheme_m = bdms_calculatescheme_m3Mapper.selectOne(calSchemeParam);
        if (bdms_calculatescheme_m != null) {
            calSchemeInfo.setCalSchemeId(bdms_calculatescheme_m.getCschemeid());
            if (bdms_calculatescheme_m.getAliasnm() != null) {
                calSchemeInfo.setCalSchemeName(bdms_calculatescheme_m.getAliasnm());
            } else {
                calSchemeInfo.setCalSchemeName(bdms_calculatescheme_m.getCschemenm());
            }
            calSchemeInfo.setForecastTime(bdms_calculatescheme_m.getDtmforecast().substring(0, 19));
            calSchemeInfo.setOperateTime(bdms_calculatescheme_m.getDtmcalculate().substring(0, 19));

            if (bdms_calculatescheme_m.getState() != null) {
                switch (bdms_calculatescheme_m.getState()) {
                    case 0:
                        calSchemeInfo.setStateInfo("新建方案");
                        break;
                    case 1:
                        calSchemeInfo.setStateInfo("计算中");
                        break;
                    case 2:
                        calSchemeInfo.setStateInfo("计算失败");
                        break;
                    case 3:
                        calSchemeInfo.setStateInfo("计算完成");
                }
            }
            calSchemeInfo.setState(bdms_calculatescheme_m.getState());
            calSchemeInfo.setUserId(String.valueOf(bdms_calculatescheme_m.getUserid()));
            calSchemeInfo.setForecastBeginTime(bdms_calculatescheme_m.getDtmstart().substring(0, 19));
            calSchemeInfo.setForecastEndTime(bdms_calculatescheme_m.getDtmend().substring(0, 19));
            calSchemeInfo.setDescription(bdms_calculatescheme_m.getRemark());
            jsonResult.setData(calSchemeInfo);
            jsonResult.setSucceeded(true);
            jsonResult.setStatusCode(200);
            jsonResult.setRemark("查询成功");
        }else {
            jsonResult.setData("未查询到相关计算方案信息");
            jsonResult.setSucceeded(true);
            jsonResult.setStatusCode(201);
            jsonResult.setRemark("查询失败");
        }
        return jsonResult;
    }

    @Override
    public BDMS_CALCULATESCHEME_M queryByCalId(String calSchemeId) {
        return bdms_calculatescheme_m3Mapper.queryByCalId(calSchemeId);
    }

    @Override
    public List<BDMS_CALCULATESCHEME_M> selectAllByPid(Integer projectId, String calSchemeId, String startTime, String endTime, boolean isForecastTime) {
        return bdms_calculatescheme_m3Mapper.selectAllByPid(projectId, calSchemeId, startTime, endTime, isForecastTime);
    }



    @Override
    public int insert(BDMS_CALCULATESCHEME_M bdms_calculatescheme_m) {
        return bdms_calculatescheme_m3Mapper.insert(bdms_calculatescheme_m);
    }

    @Override
    public int update(String calSchemeId, String calSchemeName, String description) {
        return bdms_calculatescheme_m3Mapper.update(calSchemeId, calSchemeName,description);
    }

    @Override
    public BDMS_CALCULATESCHEME_M seletcById(Integer projectId, String calSchemeId) {
        return bdms_calculatescheme_m3Mapper.selectById(projectId,calSchemeId);
    }


}
